//
//  StoreGoodsCollectionCell.m
//  ArtDog
//
//  Created by dllo on 16/9/7.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "StoreGoodsCollectionCell.h"
#import "StoreDerivativeList.h"
#import "UIImageView+WebCache.h"
#import "HomeExhibitWorkList.h"
#import "HLMacro.h"

@interface StoreGoodsCollectionCell ()
@property (weak, nonatomic) IBOutlet UIImageView *soundImage;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *autorTrailing;

@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UILabel *namelLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *autorLabel;
@property (weak, nonatomic) IBOutlet UILabel *typeLabel;
@property (weak, nonatomic) IBOutlet UIView *lineView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topLayout;
@property (weak, nonatomic) IBOutlet UIImageView *viewerImage;

@end

@implementation StoreGoodsCollectionCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)prepareForReuse
{
    [super prepareForReuse];
    _namelLabel.text = @"";
    _priceLabel.text = @"";
    _autorLabel.text = @"";
    _typeLabel.text = @"";
    _lineView.hidden = YES;
    _soundImage.hidden = YES;
}

- (void)setDerivativeModel:(StoreDerivativeList *)derivativeModel
{
    _derivativeModel = derivativeModel;
    
    [_imageView sd_setImageWithURL:[NSURL URLWithString:derivativeModel.pictureUrl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    _namelLabel.text = derivativeModel.goodsName;
    _priceLabel.text = [NSString stringWithFormat:@"¥ %@", derivativeModel.sellingPrice];
    _namelLabel.textAlignment = NSTextAlignmentCenter;
    _autorLabel.textAlignment = NSTextAlignmentRight;
    _priceLabel.textAlignment = NSTextAlignmentCenter;
    _autorLabel.hidden = YES;
    _typeLabel.hidden = YES;
    _lineView.hidden = YES;
    _viewerImage.hidden = YES;
    _topLayout.constant = 15;
    _autorTrailing.constant = 5;
}

- (void)setExhibitWorkModel:(HomeExhibitWorkList *)exhibitWorkModel
{
    _exhibitWorkModel = exhibitWorkModel;
    [_imageView sd_setImageWithURL:[NSURL URLWithString:exhibitWorkModel.worksPic] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    _namelLabel.text = exhibitWorkModel.workName;
    _priceLabel.text = [NSString stringWithFormat:@"%@", exhibitWorkModel.viewerNum];
    _autorLabel.hidden = NO;
    _autorLabel.text = [@"作者：" stringByAppendingString:exhibitWorkModel.author];
    _typeLabel.hidden = YES;
    _lineView.hidden = YES;
    _viewerImage.hidden = NO;
    _topLayout.constant = 35;
    _namelLabel.textAlignment = NSTextAlignmentLeft;
    _autorLabel.textAlignment = NSTextAlignmentLeft;
    _priceLabel.textAlignment = NSTextAlignmentLeft;
    _autorTrailing.constant = - SCREEN_WIDTH / 2 + 20;
    if (exhibitWorkModel.workAudio == nil) {
        _soundImage.hidden = YES;
    } else {
        _soundImage.hidden = NO;
        _soundImage.layer.borderColor = [UIColor whiteColor].CGColor;
    }
}

@end
